/**************************************************************************
 *         Copyright(c) 2007 by Sunplus mMedia  Technology Co., Ltd.       *
 *                                                                         *
 *  This software is copyrighted by and is the property of Sunplus mMedia  *
 *  Technology Co., Ltd. All rights are reserved by Sunplus mMedia Techno- *
 *  logy Co., Ltd. This software may only be used in accordance with the   *
 *  corresponding license agreement. Any unauthorized use, duplication,    *
 *  distribution, or disclosure of this software is expressly forbidden.   *
 *                                                                         *
 *  This Copyright notice "M U S T" not be removed or modified without     *
 *  prior written consent of Sunplus mMedia Technology  Co., Ltd.          *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd. reserves the right to modify this  *
 *  software without notice.                                               *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd.                                    *
 *  19-1, Innovation First Road, Science-Based Industrial Park,            *
 *  Hsin-Chu, Taiwan, R.O.C.                                               *
 *                                                                         *
 **************************************************************************/
#ifndef __SPIFUNC_H__
#define __SPIFUNC_H__

#define K_SPI2DRAM 0
#define K_SPI2USB  1

#define K_DRAM2SPI 0
#define K_USB2SPI  1

typedef struct spiId_s {
	UINT32 id;
	UINT32 blkSize;
	UINT32 tolSize;
	UINT8  bitBlkSize;
	UINT8  bufBlk;
	UINT8  eraseCmd;
} spiId_t;

extern xdata spiId_t spiDev;
//------------------------------------------------------------------------------
//Function prototype
//------------------------------------------------------------------------------
UINT8 spiRsvRead(UINT32 ,UINT32 );
UINT8 spiRsvWrite(UINT32 ,UINT32 );
UINT8 spiRsvSizeGet(UINT32 idx,UINT32 *offset,	UINT32 *);
void sfPhySectorR(UINT32 start,UINT16 count,UINT32 dmaSize,UINT32 buf, UINT32 sram);
UINT8 HAL_SPIInit(UINT8 Freq, UINT8 Mode);
void sfIdRead(UINT8 id[]);
void sfSectorErase(UINT32 addr);
UINT32 sfPhySectorW(UINT32 start, UINT16 count,UINT32 dmaSize, UINT32 buf, UINT32 sram);
UINT8 spiEraseSector(UINT32 phyAddr,UINT32 size,UINT8 print);
UINT32 spiReadAllRaw(UINT32 addr);
UINT8 spiWriteLbaToPba(UINT32 logAddr, UINT32* oldPhyAddr, UINT32* newPhyAddr, UINT16* blockNum);
#endif /*__SPIFUNC_H__*/
